/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-

   credenza-window-slot.h: Credenza window slot
 
   Copyright (C) 2008 Free Software Foundation, Inc.
  
   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.
  
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.
  
   You should have received a copy of the GNU General Public
   License along with this program; if not, write to the
   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
  
   Author: Christian Neumair <cneumair@gnome.org>
*/

#ifndef CREDENZA_WINDOW_SLOT_H
#define CREDENZA_WINDOW_SLOT_H

#include "credenza-window-pane.h"
#include "credenza-query-editor.h"
#include <glib/gi18n.h>

#define CREDENZA_TYPE_WINDOW_SLOT	 (credenza_window_slot_get_type())
#define CREDENZA_WINDOW_SLOT_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), CREDENZA_TYPE_WINDOW_SLOT, CredenzaWindowSlotClass))
#define CREDENZA_WINDOW_SLOT(obj)	 (G_TYPE_CHECK_INSTANCE_CAST ((obj), CREDENZA_TYPE_WINDOW_SLOT, CredenzaWindowSlot))
#define CREDENZA_IS_WINDOW_SLOT(obj)      (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CREDENZA_TYPE_WINDOW_SLOT))
#define CREDENZA_IS_WINDOW_SLOT_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), CREDENZA_TYPE_WINDOW_SLOT))
#define CREDENZA_WINDOW_SLOT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), CREDENZA_TYPE_WINDOW_SLOT, CredenzaWindowSlotClass))

typedef enum {
	CREDENZA_LOCATION_CHANGE_STANDARD,
	CREDENZA_LOCATION_CHANGE_BACK,
	CREDENZA_LOCATION_CHANGE_FORWARD,
	CREDENZA_LOCATION_CHANGE_RELOAD,
	CREDENZA_LOCATION_CHANGE_REDIRECT,
	CREDENZA_LOCATION_CHANGE_FALLBACK
} CredenzaLocationChangeType;

struct CredenzaWindowSlotClass {
	GObjectClass parent_class;

	/* wrapped CredenzaWindowInfo signals, for overloading */
	void (* active)   (CredenzaWindowSlot *slot);
	void (* inactive) (CredenzaWindowSlot *slot);

	void (* update_query_editor) (CredenzaWindowSlot *slot);
};

/* Each CredenzaWindowSlot corresponds to
 * a location in the window for displaying
 * a CredenzaView.
 *
 * For navigation windows, this would be a
 * tab, while spatial windows only have one slot.
 */
struct CredenzaWindowSlot {
	GObject parent;

	CredenzaWindowPane *pane;

	/* content_box contains
 	 *  1) an event box containing extra_location_widgets
 	 *  2) the view box for the content view
 	 */
	GtkWidget *content_box;
	GtkWidget *extra_location_frame;
	GtkWidget *extra_location_widgets;
	GtkWidget *view_box;

	CredenzaView *content_view;
	CredenzaView *new_content_view;

	/* Information about bookmarks */
	CredenzaBookmark *current_location_bookmark;
	CredenzaBookmark *last_location_bookmark;

	/* Current location. */
	GFile *location;
	char *title;
	char *status_text;

	CredenzaFile *viewed_file;
	gboolean viewed_file_seen;
	gboolean viewed_file_in_trash;

	gboolean allow_stop;

	CredenzaQueryEditor *query_editor;

	/* New location. */
	CredenzaLocationChangeType location_change_type;
	guint location_change_distance;
	GFile *pending_location;
	char *pending_scroll_to;
	GList *pending_selection;
	CredenzaFile *determine_view_file;
	GCancellable *mount_cancellable;
	GError *mount_error;
	gboolean tried_mount;

	GCancellable *find_mount_cancellable;

	gboolean visible;
};

GType   credenza_window_slot_get_type (void);

char *  credenza_window_slot_get_title			   (CredenzaWindowSlot *slot);
void    credenza_window_slot_update_title		   (CredenzaWindowSlot *slot);
void    credenza_window_slot_update_icon		   (CredenzaWindowSlot *slot);
void    credenza_window_slot_update_query_editor	   (CredenzaWindowSlot *slot);

GFile * credenza_window_slot_get_location		   (CredenzaWindowSlot *slot);
char *  credenza_window_slot_get_location_uri		   (CredenzaWindowSlot *slot);

void    credenza_window_slot_close			   (CredenzaWindowSlot *slot);
void    credenza_window_slot_reload			   (CredenzaWindowSlot *slot);

void			credenza_window_slot_open_location	      (CredenzaWindowSlot	*slot,
								       GFile			*location,
								       gboolean			 close_behind);
void			credenza_window_slot_open_location_with_selection (CredenzaWindowSlot	    *slot,
									   GFile		    *location,
									   GList		    *selection,
									   gboolean		     close_behind);
void			credenza_window_slot_open_location_full       (CredenzaWindowSlot	*slot,
								       GFile			*location,
								       CredenzaWindowOpenMode	 mode,
								       CredenzaWindowOpenFlags	 flags,
								       GList			*new_selection);
void			credenza_window_slot_stop_loading	      (CredenzaWindowSlot	*slot);

void			credenza_window_slot_set_content_view	      (CredenzaWindowSlot	*slot,
								       const char		*id);
const char	       *credenza_window_slot_get_content_view_id      (CredenzaWindowSlot	*slot);
gboolean		credenza_window_slot_content_view_matches_iid (CredenzaWindowSlot	*slot,
								       const char		*iid);

void                    credenza_window_slot_connect_content_view     (CredenzaWindowSlot       *slot,
								       CredenzaView             *view);
void                    credenza_window_slot_disconnect_content_view  (CredenzaWindowSlot       *slot,
								       CredenzaView             *view);

#define credenza_window_slot_go_to(slot,location, new_tab) \
	credenza_window_slot_open_location_full(slot, location, CREDENZA_WINDOW_OPEN_ACCORDING_TO_MODE, \
						 0, \
						NULL)

#define credenza_window_slot_go_to_with_selection(slot,location,new_selection) \
	credenza_window_slot_open_location_with_selection(slot, location, new_selection, FALSE)

void	credenza_window_slot_go_home			   (CredenzaWindowSlot *slot);
void    credenza_window_slot_go_up			   (CredenzaWindowSlot *slot,
							    gboolean           close_behind);

void    credenza_window_slot_set_content_view_widget	   (CredenzaWindowSlot *slot,
							    CredenzaView       *content_view);
void    credenza_window_slot_set_viewed_file		   (CredenzaWindowSlot *slot,
							    CredenzaFile      *file);
void    credenza_window_slot_set_allow_stop		   (CredenzaWindowSlot *slot,
							    gboolean	    allow_stop);
void    credenza_window_slot_set_status			   (CredenzaWindowSlot *slot,
							    const char	 *status);

void    credenza_window_slot_add_extra_location_widget     (CredenzaWindowSlot *slot,
							    GtkWidget       *widget);
void    credenza_window_slot_remove_extra_location_widgets (CredenzaWindowSlot *slot);

void    credenza_window_slot_add_current_location_to_history_list (CredenzaWindowSlot *slot);

void    credenza_window_slot_is_in_active_pane (CredenzaWindowSlot *slot, gboolean is_active);

#endif /* CREDENZA_WINDOW_SLOT_H */
